package com.company;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.core.env.SimpleCommandLinePropertySource;

@SpringBootApplication(scanBasePackages = {"com.company"})
@EnableCaching
public class CompanyApplication {


  private static final Logger logger = LoggerFactory.getLogger(CompanyApplication.class);

  public static void main(String[] args) {
    SpringApplication app = new SpringApplication(CompanyApplication.class);
    app.setBannerMode(Banner.Mode.OFF);
    SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);
    app.setAdditionalProfiles(getDefaultProfile(source));
    app.run(args);
  }

  private static String getDefaultProfile(SimpleCommandLinePropertySource source) {
    if (source.containsProperty("spring.profiles.active")) {
      logger.info("Running with Spring profile(s) : {}",
          source.getProperty("spring.profiles.active"));
      return source.getProperty("spring.profiles.active");
    }

    logger.warn("No Spring profile configured, running with default configuration: local.");
    return "local";
  }
}
